//
//  ICRedPacketResultTableViewCell.m
//  ICome
//
//  Created by luoziheng on 2016/11/11.
//  Copyright © 2016年 iCom. All rights reserved.
//

#import "ICRedPacketResultTableViewCell.h"
#import "ICHeadImageView.h"
#import "UIImage+AvatarGeneration.h"
#import "ICHeaderFile.h"

@interface ICRedPacketResultTableViewCell()
@property (nonatomic, strong) ICHeadImageView *headerImageView;  // 头像
@property (nonatomic, strong) UILabel *nameLabel; // 姓名
@property (nonatomic, strong) UILabel *dateLabel; // 日期
@property (nonatomic, strong) UILabel *workPointLabel; // 工分
@end

@implementation ICRedPacketResultTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)cell reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:cell reuseIdentifier:reuseIdentifier];
    if (self) {
        [self layoutSubview];
    }
    return self;
}

- (void)layoutSubview {
    [self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.mas_equalTo(40 * Level);
        make.height.mas_equalTo(40 * Level);
    }];
    [self.workPointLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(18);
        make.right.equalTo(self.mas_right).offset(-15);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(45 * Level/2);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerImageView.mas_top);
        make.left.equalTo(self.headerImageView.mas_right).offset(13);
        make.right.equalTo(self.workPointLabel.mas_left).offset(-5);
        make.height.mas_equalTo(45 * Level/2+3);
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom);
        make.left.equalTo(self.nameLabel.mas_left);
        make.right.equalTo(self.nameLabel.mas_right);
        make.height.mas_equalTo(45 * Level/2-3);
    }];
}

- (void)setModel:(ICClickRedPacketListModel *)model {
    
    NSString *URL = [ICTools getOglImageURL:([ICMessageDatabase getPhotoIdWithEId:model.eId])];
    [UIImage addAvatariamgeView:self.headerImageView.imageView withUrlStr:URL witheId:model.eId withName:[ICMessageDatabase getUserNameWithEId:model.eId]];
//    [self.headerImageView.imageView sd_setImageWithURL:[NSURL URLWithString:OGLIMAGEURL([ICMessageDatabase getPhotoIdWithEId:model.eId])] placeholderImage:[UIImage imageNamed:@"App_personal_headimg"]];
    self.nameLabel.text = [ICMessageDatabase getUserNameWithEId:model.eId];
    self.dateLabel.text = [model.createDate getDateWithTimestamp:model.createDate];
    self.workPointLabel.text = model.amount;
}

#pragma mark - Getter

- (ICHeadImageView *)headerImageView {
    if (!_headerImageView) {
        _headerImageView = [[ICHeadImageView alloc] init];
        [self.contentView addSubview:_headerImageView];
    }
    return _headerImageView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = ICRGB(0x000000);
        _nameLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_nameLabel];
    }
    return _nameLabel;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.textColor = ICRGB(0x999999);
        _dateLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_dateLabel];
    }
    return _dateLabel;
}

- (UILabel *)workPointLabel {
    if (!_workPointLabel) {
        _workPointLabel = [[UILabel alloc] init];
        _workPointLabel.textColor = ICRGB(0x000000);
        _workPointLabel.font = [UIFont systemFontOfSize:15];
        _workPointLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_workPointLabel];
    }
    return _workPointLabel;
}


@end
